﻿@using SimpleIdServer.CredentialIssuer.Domains;
@inject DialogService dialogService

<RadzenStack Gap="1rem">
    <!-- Type -->
    <RadzenFormField Text="@Global.Type" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenTextBox @bind-Value="@Form.Type"></RadzenTextBox>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.TypeHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Format -->
    <RadzenFormField Text="@Global.Format" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenDropDown @bind-Value="@Form.Format"
                            Data="@SupportedFormats" />
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.CredentialConfigurationFormatHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Scope -->
    <RadzenFormField Text="@Global.Scope" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenTextBox @bind-Value="@Form.Scope"></RadzenTextBox>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.CredentialConfigurationScopeHelper</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Json Ld Context -->
    <RadzenFormField Text="@Global.JsonLdContext" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenTextBox @bind-Value="@Form.JsonLdContext"></RadzenTextBox>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.JsonLdContextDescription</RadzenText>
        </Helper>
    </RadzenFormField>
    <!-- Base url -->
    <RadzenFormField Text="@Global.BaseUrl" Variant=Variant.Outlined>
        <ChildContent>
            <RadzenTextBox @bind-Value="@Form.BaseUrl"></RadzenTextBox>
        </ChildContent>
        <Helper>
            <RadzenText TextStyle="TextStyle.Caption">@Global.BaseUrlDescription</RadzenText>
        </Helper>
    </RadzenFormField>
    <div>
        <RadzenButton class="mb-1" Click="@(args => Add())" Icon="save" Text="@Global.Save" ButtonStyle="ButtonStyle.Primary" Size="ButtonSize.Medium"></RadzenButton>
    </div>
</RadzenStack>

@code {
    List<string> SupportedFormats = new List<string>
    {
        "ldp_vc",
        "jwt_vc_json-ld",
        "jwt_vc_json"
    };

    record AddCredentialConfigurationForm
    {
        public string Type { get; set; }
        public string Format { get; set; }
        public string Scope { get; set; }
        public string JsonLdContext { get; set; }
        public string BaseUrl { get; set; }
    }

    AddCredentialConfigurationForm Form = new AddCredentialConfigurationForm();

    void Add()
    {
        dialogService.Close(new CredentialConfiguration
        {
            Type = Form.Type,
            Format = Form.Format,
            Scope = Form.Scope,
            JsonLdContext = Form.JsonLdContext,
            BaseUrl = Form.BaseUrl
        });
    }
}
